package com.zyj.myapplication.Adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.MediaController;
import android.widget.VideoView;
import com.zyj.myapplication.Activity.CoachListActivity;
import com.zyj.myapplication.Javabean.VideoList;
import com.zyj.myapplication.R;
import java.util.List;

/**
 * Created by Lee1 on 2017/10/30.
 */

public class DashiClassInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
    private Context mContext;
    private static  int UpUI=1;
    private List mDataList;//数据存储
    private LayoutInflater mLayoutInflater;//准备布局

    public DashiClassInfoAdapter(Context mContext, List mDataList) {
        this.mContext = mContext;
        this.mDataList = mDataList;
        mLayoutInflater = LayoutInflater.from(mContext);
    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mLayoutInflater.from(parent.getContext()).inflate(R.layout.cardview_dashiclassinfo, parent, false);
        return new VideoViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final VideoList.MvideoBean entity = (VideoList.MvideoBean) mDataList.get(position);
        VideoViewHolder videoViewHolder=(VideoViewHolder)holder;
        if (null == entity)
            return;
        MediaController controller=new MediaController(mContext);
        String videoAddress="http://172.24.10.175/workout/Uploads/tvideo/video/" +entity.getUrl();
        controller.setMediaPlayer(videoViewHolder.videoView);
        videoViewHolder.videoView.setMediaController(controller);
        videoViewHolder.videoView.setVideoPath(Uri.parse(videoAddress).toString());
        videoViewHolder.videoView.start();
        videoViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext,CoachListActivity.class);
                intent.putExtra("coach_id",entity.getId());
                mContext.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    public class VideoViewHolder extends RecyclerView.ViewHolder{
        VideoView videoView;
        public VideoViewHolder(View itemView) {
            super(itemView);
            videoView=(VideoView)itemView.findViewById(R.id.videoView);
        }
    }
}
